;File: level_drawer.lisp
;Abstract: 
;	-Converts level data into a mutliline human-readable string
;	-Creates function Get-Level-String (level)


(defun Get-Level-String (level)
	(
		let ((formatted-level (reformat-level level)))
		(
			concatString (mapcar #'get-row-string formatted-level) v-separator
		)
	)
)

;-----------------------------------------------------
;----------------------Constants----------------------
;-----------------------------------------------------

;	_____
;	|   |
;	|   |
;	|   |
;	-----
(defvar shape1 '("_____" "|   |" "|   |" "|   |" "-----"))

;	     
;	  A
;	 / \ 
;	/   \	
;	-----
(defvar shape2'("     " "  A  " " / \\ " "/   \\" "-----"))

;	  A
;	 / \
;	< X >
;	 \ /
;	  V
(defvar shape3 '("  A  " " / \\ " "< X >" " \\ / " "  V  "))

;	\---/
;	|\ /|
;	| X |
;	|/ \|
;	/---\
(defvar shape4 	'("\\---/" "|\\ /|" "| X |" "|/ \\|" "/---\\"))

;	 ___
;	/   \
;	| O |
;	\   /
;	 ---
(defvar shape5 	'(" ___ " "/   \\" "| O |" "\\   /" " --- "))

(defvar shape-blank 	'("     " "     " "     " "     " "     "))

(defvar h-separator '"  ")

(defvar v-separator '"")

(defvar z-separator '"
")

(defun get-shape (id)
	(case id
		(1 shape1)
		(2 shape2)
		(3 shape3)
		(4 shape4)
		(5 shape5)
		(0 shape-blank)
		(otherwise nil)
	)
)

;-----------------------------------------------------
;----------------------Reformatter--------------------
;-----------------------------------------------------

(defun reformat-level (level)
	(
		reverse (transpose (flip-level level))
	)
)

(defun flip-level (level)
	(
		mapcar #'reverse level
	)
)

(defun transpose (mat)
	(
		if (null (caar mat)) nil
		(
			cons (mapcar #'car mat) 
				(transpose (remove-Col mat))
		)
	)
)

(defun remove-Col (level)
	(
		mapcar #'cdr level
	)
)

;-----------------------------------------------------
;---------------------Drawing-------------------------
;-----------------------------------------------------

(defun test-draw (str)
	(progn 
		(princ str)
		""
	)
)

(defun get-row-string (row)
	(
		let ((shape-row (make-shape-row row)))
			(
				concatString (mapcar #'get-subrow-string shape-row) "
"
			)
	)
)

(defun get-subrow-string (subrow)
	(
		concatString subrow h-separator
	)
)

(defun make-shape-row (row)
	(
		transpose (mapcar #'get-shape row)
	)
)

(defun draw-shape (shape-id)
	(
		concatenate 'string (car (get-shape shape-id)) h-separator
	)
)

(defun concatString (lst separator)
  (if (listp lst)
      (let ((result ""))
        (dolist (item lst)
          (if (stringp item)
              (setq result (concatenate 'string result item separator))))
        result)
  )
)